package com.zhuiyun.educations.api.homepage.mapper;

import com.zhuiyun.educations.api.homepage.entity.CourseVo;
import com.zhuiyun.educations.api.homepage.entity.Rotaion;
import com.zhuiyun.educations.api.newCourse.entity.CourseUnit;
import com.zhuiyun.educations.api.newCourse.entity.DTO.CourseDTO;
import com.zhuiyun.educations.api.newCourse.entity.UnitJoint;
import com.zhuiyun.educations.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description:
 * @ClassName: CourseVoMapper
 * @Author: YB
 * @Date: 2023/6/21 11:40
 * @Version: 1.0
 */
@Mapper
public interface CourseVoMapper extends BaseMapper<CourseVo> {
    /**
     * @Author yuanb
     * @Description pc端首页活数据免费数据
     * @Date 2023/6/21 16:19
     * @Return com.zhuiyun.educations.common.response.CommonResult
     *
     */
    @Select("SELECT i.*,t.t_name,p.price FROM course_info i \n" +
            "LEFT JOIN teacher t \n" +
            "ON i.teacher_id = t.id \n" +
            "LEFT JOIN price p \n" +
            "ON i.id = p.course_id \n" +
            "WHERE i.del_flag = 0 AND \n" +
            "i.course_type = 0 AND \n" +
            "i.pay_type = 0 AND \n" +
            "i.course_status = 0 AND \n" +
            "i.type = 1\n")
    List<CourseVo> homePageAllFree();

    /**
     * @Author yuanb
     * @Description 轮播图
     * @Date 2023/6/21 16:34
     * @Return com.zhuiyun.educations.common.response.CommonResult
     *
     */
    @Select("SELECT id,image_id from rotation_image WHERE id= #{id} and del_flag=0")
    Rotaion CarouselAll(Rotaion rotaion);

    /**
     * @Author yuanb
     * @Description pc端首页活数据收费数据
     * @Date 2023/6/21 16:19
     * @Return com.zhuiyun.educations.common.response.CommonResult
     *
     */
    @Select("SELECT c.id,c.course_title,c.pay_type,c.image_id,c.create_time,t.t_name,p.price FROM course c\n" +
            "LEFT JOIN teacher t\n" +
            "ON c.teacher_id = t.id\n" +
            "LEFT JOIN price p \n" +
            "on c.id = p.id\n" +
            "WHERE p.del_flag = 0 AND c.pay_type = 0")
    List<CourseVo> homePageAllcharge();

    /**
    * @Author MJL
    * @Description todo pc端新课推荐数据
    * @Date 2023/6/27 15:41
    * @Return  * @param null
    */
    @Select("SELECT i.*,t.t_name,p.price FROM course_info i \n" +
            "LEFT JOIN teacher t \n" +
            "ON i.teacher_id = t.id \n" +
            "LEFT JOIN price p \n" +
            "ON i.id = p.course_id \n" +
            "WHERE i.del_flag = 0 AND \n" +
            "i.course_type = 0 AND \n" +
            "i.pay_type = 1 AND \n" +
            "i.course_status = 0 ORDER BY i.create_time DESC")
    List<CourseVo> homePageNewAllCharge();

    /**
    * @Author MJL
    * @Description todo pc端微专业数据
    * @Date 2023/6/27 20:40
    * @Return  * @param null
    */
    @Select("SELECT i.*,t.t_name,p.price FROM course_info i \n" +
            "LEFT JOIN teacher t \n" +
            "ON i.teacher_id = t.id \n" +
            "LEFT JOIN price p \n" +
            "ON i.id = p.course_id \n" +
            "WHERE i.del_flag = 0 AND \n" +
            "i.course_type = 0 AND \n" +
            "i.pay_type = 1 AND \n" +
            "i.course_status = 0 AND \n" +
            "i.type = 2")
    List<CourseVo> homePageMicroAllCharge();

    /**
    * @Author MJL
    * @Description todo pc端获取精选课数据
    * @Date 2023/6/28 15:41
    * @Return  * @param null
    */
    @Select("SELECT i.*,t.t_name,p.price FROM course_info i \n" +
            "LEFT JOIN teacher t \n" +
            "ON i.teacher_id = t.id \n" +
            "LEFT JOIN price p \n" +
            "ON i.id = p.course_id \n" +
            "WHERE i.del_flag = 0 AND \n" +
            "i.course_type = 0 AND \n" +
            "i.pay_type = 1 AND \n" +
            "i.course_status = 0 AND \n" +
            "i.type = 0")
    List<CourseVo> homePageSelected();
    @Select("SELECT i.*,t.t_name,p.price FROM course_info i \n" +
            "LEFT JOIN teacher t \n" +
            "ON i.teacher_id = t.id \n" +
            "LEFT JOIN price p \n" +
            "ON i.id = p.course_id \n" +
            "WHERE i.del_flag = 0 AND \n" +
            "i.course_type = 0 AND \n" +
            "i.course_status = 0 AND \n" +
            "i.id = #{id}")
    List<CourseVo> homePageSelectedById(@Param("id") Integer id);
    @Select("SELECT * FROM course_unit WHERE course_id = #{id} ")
    List<CourseUnit> homePageUnitById(@Param("id") Integer id);
    @Select("SELECT * FROM unit_joint WHERE joint_status = 0 and  unit_id=#{id}")
    List<UnitJoint> homePageJointById( Integer id);
    /**
    * @Author MJL
    * @Description todo pc端大课程分类
    * @Date 2023/6/29 11:09
    * @Return  * @param null
    */
    @Select("select id,subject_type from subject where del_flag = 0")
    List<CourseVo> BigClassList();

    /**
    * @Author MJL
    * @Description todo pc端小课程数据
    * @Date 2023/6/29 14:03
    * @Return  * @param null
    */
    @Select("SELECT c.course_name,c.subject_id,s.subject_type FROM course c \n" +
            "LEFT JOIN `subject` s \n" +
            "ON c.subject_id = s.id \n" +
            "WHERE c.del_flag = 0 and " +
            "c.subject_id = #{subjectId}")
    List<CourseVo> SmallClassList(Integer subjectId);

    /**
    * @Author 杨友朋
    * @Description TODO 查询详细页面
    * @Date 2023/7/11 16:26
    * @Return
    * @param
    */

    @Select("select i.id,i.course_title,i.introduction,i.teacher_id,i.course_type,i.pay_type,i.course_status,t.*,p.price " +
            "from course_info i left join `teacher` t on t.id=i.teacher_id left join `price` p on i.id=p.course_id " +
            "where i.id=#{id} and i.del_flag=0 and i.course_status='0'")
    CourseDTO selectCourseInfo(Integer id);
}
